package com.nep.NEPM.controller;

import com.nep.common.util.SceneSwitcherUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * AQI指数分布统计界面控制器
 */
public class AQIDistributeStatisController {
    @FXML
    private Button btn_OUT;
    @FXML
    private Button btn_Supervisor;
    @FXML
    private Button btn_ConfirmAQI;
    @FXML
    private Button btn_ProvinceGro;

    @FXML
    private TableView<AQIData> aqiTableView;
    @FXML
    private TableColumn<AQIData, String> colLevel;
    @FXML
    private TableColumn<AQIData, String> colDescription;
    @FXML
    private TableColumn<AQIData, Integer> colCount;

    /**
     * 初始化方法，在界面加载时自动调用
     */
    @FXML
    private void initialize() {
        // 配置表格列与数据模型的映射关系
        colLevel.setCellValueFactory(new PropertyValueFactory<>("level"));
        colDescription.setCellValueFactory(new PropertyValueFactory<>("description"));
        colCount.setCellValueFactory(new PropertyValueFactory<>("count"));

        // 加载AQI指数分布示例数据
        ObservableList<AQIData> data = FXCollections.observableArrayList(
                new AQIData("优", "空气质量令人满意，基本无空气污染", 120),
                new AQIData("良", "空气质量可接受，但某些污染物可能对极少数异常敏感人群健康有较弱影响", 85),
                new AQIData("轻度污染", "易感人群症状有轻度加剧，健康人群出现刺激症状", 30),
                new AQIData("中度污染", "进一步加剧易感人群症状，可能对健康人群心脏、呼吸系统有影响", 15),
                new AQIData("重度污染", "心脏病和肺病患者症状显著加剧，运动耐受力降低，健康人群普遍出现症状", 8),
                new AQIData("严重污染", "健康人群运动耐受力降低，有明显强烈症状，提前出现某些疾病", 2)
        );

        aqiTableView.setItems(data);
    }

    /**
     * 返回上一级界面
     */
    @FXML
    private void OutToMain() {
        SceneSwitcherUtil.switchScene(btn_OUT, "/com/nep/NEPM/view/IndexView.fxml");
    }

    /**
     * 跳转到公众监督数据列表
     */
    @FXML
    private void toSupervisorList() {
        SceneSwitcherUtil.switchScene(btn_Supervisor, "/com/nep/NEPM/view/SupervisorListView.fxml");
    }

    /**
     * 跳转到确认AQI数据列表
     */
    @FXML
    private void toConfirmAQIList() {
        SceneSwitcherUtil.switchScene(btn_ConfirmAQI, "/com/nep/NEPM/view/ConfirmAQIListView.fxml");
    }

    /**
     * 跳转到省分组检查统计
     */
    @FXML
    private void toProvinceGro() {
        SceneSwitcherUtil.switchScene(btn_ProvinceGro, "/com/nep/NEPM/view/ProvinceGroView.fxml");
    }

    /**
     * AQI数据模型类
     */
    public static class AQIData {
        private final String level;        // AQI等级
        private final String description;  // 等级描述
        private final Integer count;      // 分布数量

        public AQIData(String level, String description, Integer count) {
            this.level = level;
            this.description = description;
            this.count = count;
        }

        public String getLevel() { return level; }
        public String getDescription() { return description; }
        public Integer getCount() { return count; }
    }
}